<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

class SloganService {

    public static function add($IdNguoiDung) {
        $slogan = new SloganDaDuyet();
        $slogan->NguoiDungId = $IdNguoiDung;
        return $slogan->save();
    }

    public static function remove($IdNguoiDung) {
        $slogan = SloganDaDuyet::model()->findByAttributes(array('NguoiDungId' => $IdNguoiDung));
        return $slogan->delete();
    }

    public static function getAll() {
        return VwSlogan::model()->findAll();
    }

    public static function getRandom() {
        $slogans = SloganService::getAll();
        $count = count($slogans);

        if ($count == 0) {
            return null;
        }

        $offset = rand(0, $count-1);
        return $slogans[$offset];
    }

}
